package com.minsus.secretmailbox;

import java.util.regex.Pattern;

/**
 * @date 2011-09-22
 * 
 * @author kkm 특정 값의 형식을 체크하기 위한 클래스
 * 
 * Singleton Pattern
 * 
 */
public class CheckValue {
	private static CheckValue mInstance = null;

	private final Pattern EMAIL_ADDRESS_PATTERN = Pattern
			.compile("[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@"
					+ "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + "(" + "\\."
					+ "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + ")+");
	private final Pattern PHONE_NUMBER_PATTERN = Pattern
			.compile("^01(?:0|1|[6-9])-(?:\\d{3}|\\d{4})-\\d{4}$");

	// Constructor
	private CheckValue() {
	}

	public static CheckValue getInstance() {

		if (CheckValue.mInstance == null) {
			synchronized (CheckValue.class) {
				if (CheckValue.mInstance == null) {
					CheckValue.mInstance = new CheckValue();
				}
			}
		}

		return CheckValue.mInstance;
	}

	/**
	 * Email의 유효성 체크
	 * 
	 * @param email
	 * @return
	 */
	public boolean checkTypeEmail(String email) {
		return EMAIL_ADDRESS_PATTERN.matcher(email).matches();
	}

	/**
	 * Mobile Phone Number의 유효성 체크
	 * 
	 * @param number
	 * @return
	 */
	public boolean checkTypeMobileNumber(String number) {
		return PHONE_NUMBER_PATTERN.matcher(number).matches();
	}
} // end of class CheckValue
